﻿/******************************************************************
** 文 件 名: Bu_AuditTable_List.aspx.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-3-21 23:53:18
** 描    述: 内部审核作业表列表页面
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseLibrary;
using Honestysoft.BaseObject;
using Honestysoft.BaseLibrary.ExceptionHandling;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
	public partial class Bu_AuditTable_List : BasePage
	{	
		protected override void Page_Load(object sender, EventArgs e)
        {
			base.Page_Load(sender, e);
            if (!IsPostBack)
            {		
				AspNetPager1.PageSize = Globals.PageSize;
				BindControl();
                Bind();
            }
        }
		/// <summary>
        /// 绑定页面控件。
        /// </summary>
		private void BindControl()
		{
            //btnAdd.Enabled = false;
            //AuditUtils.AuditTreeNodeType nodeType = (AuditUtils.AuditTreeNodeType)int.Parse(Request.QueryString[AuditUtils.ParamName_AuditNodeType]);
            //if (nodeType == AuditUtils.AuditTreeNodeType.Contract)
            //{
            //    btnAdd.Enabled = true;
            //}
            //ControlHelper.BindDictionary(ddlProjectCategory, "ProjectCategory");
            //ControlHelper.InsertAllItemAndSelect(ref ddlProjectCategory);
            //ControlHelper.BindDictionary(ddlContractCategory, "ContractCategory");
            //ControlHelper.InsertAllItemAndSelect(ref ddlContractCategory);
		}
		/// <summary>
        /// 设置弹出窗体大小
		/// 基类中已自动做控制。默认宽度800，高度600
        /// </summary>
		protected override void SetDialogSize()
		{
			//base.SetDialogSize();
			//重载宽度，高度
            ModalDialogSize.EditHeight = 768;
            ModalDialogSize.EditWidth = 900;
            ModalDialogSize.ViewHeight = 768;
            ModalDialogSize.ViewWidth = 900;
		}
		/// <summary>
        /// 根据权限控制页面按钮.
        /// 基类中已自动做控制。
        /// </summary>
        protected override void ButtonSetting()
        {
            base.ButtonSetting();
            //使用PageSecurity检查权限
            if (PageSecurity.Add)
            {
                btnAdd.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Audit/AddAuditTable.aspx?FunctionID="+FunctionID+ "&BatchID="+Request.QueryString["BatchID"]+"&ContractID="+Request.QueryString["ContractID"]+"',450,300, '新增内部审核作业表');return false;");
            }
        }
		/// <summary>
        /// 得到查询参数
        /// </summary>
        /// <returns>查询参数</returns>
		private QueryParameters GetQueryParameters()
		{
            //AuditUtils.AuditTreeNodeType nodeType = (AuditUtils.AuditTreeNodeType)int.Parse(Request.QueryString[AuditUtils.ParamName_AuditNodeType]);
			QueryParameters queryParameters = new QueryParameters();
            //if (nodeType == AuditUtils.AuditTreeNodeType.Project)
            //{
            //    queryParameters.Add("ProjectID",Request.QueryString["ID"], QueryParameters.OperatorType.Equal);
            //}
            if (txtProjectSN.Text.Trim().Length > 0)
            {
                queryParameters.Add("ProjectSN", txtProjectSN.Text.Trim(), QueryParameters.OperatorType.Like);
            }
            //if(txtProjectCode.Text.Trim().Length > 0)
            //{
            //    queryParameters.Add("ProjectCode",txtProjectCode.Text,QueryParameters.OperatorType.Like);
            //}
			if(txtProjectName.Text.Trim().Length > 0)
			{
				queryParameters.Add("ProjectName",txtProjectName.Text,QueryParameters.OperatorType.Like);
			}
            //if (nodeType == AuditUtils.AuditTreeNodeType.Contract)
            //{
            //    queryParameters.Add("ContractID", Request.QueryString["ID"], QueryParameters.OperatorType.Equal);
            //}
			if(txtContractName.Text.Trim().Length > 0)
			{
				queryParameters.Add("ContractName",txtContractName.Text,QueryParameters.OperatorType.Like);
			}
            if (txtCode.Text.Trim().Length > 0)
            {
                queryParameters.Add("Code", txtCode.Text, QueryParameters.OperatorType.Like);
            }
            //if (nodeType == AuditUtils.AuditTreeNodeType.Batch)
            //{
            //    queryParameters.Add("BatchID", Request.QueryString["ID"], QueryParameters.OperatorType.Equal);
            //}
            if (txtBatchNo.Text.Trim().Length > 0)
            {
                queryParameters.Add("BatchNo", Convert.ToInt32(txtBatchNo.Text), QueryParameters.OperatorType.Equal);
            }
			return queryParameters;
		}
		/// <summary>
        /// 得到排序参数
        /// </summary>
        /// <returns></returns>
		private OrderParameters GetOrderParameters()
		{
			OrderParameters orderParameters = new OrderParameters();
			//添加排序列
            orderParameters.Add("BatchNo", OrderParameters.OrderDirection.Desc);
            orderParameters.Add("Code");
			return orderParameters;
		}
		/// <summary>
        /// 绑定列表
        /// </summary>
		private void Bind()
        {
			QueryParameters queryParameters = GetQueryParameters();
			OrderParameters orderParameters = GetOrderParameters();
			BaseBusinessLogic<Bu_AuditTable> baseLogic = new BaseBusinessLogic<Bu_AuditTable>();
            int pageCount = 0, recordCount = 0;
            DataTable dtList = baseLogic.GetTablePaging(queryParameters, orderParameters, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out recordCount);
            dtList.Columns.Add("CurrentNode", typeof(string));
            dtList.Columns.Add("CurrentUser", typeof(string));
            AspNetPager1.RecordCount = recordCount;
            List<string> lsID = new List<string>();
            foreach(DataRow dr in dtList.Rows)
            {
                lsID.Add(dr["ID"].ToString());
            }
            Honestysoft.Workflow.BusinessFacade.WFApply.Work IWork = new Workflow.BusinessFacade.WFApply.Work();
            List<Workflow.Model.WFWorkItem> lsWorks = IWork.GetCurrentWorkItemList(((int)EnumItem.WFBill.AuditTable).ToString(), lsID);
            if (lsWorks != null && lsWorks.Count > 0)
            {
                List<Workflow.Model.WFWorkItem> lsFind = null;
                string node = "", user = "";
                foreach (DataRow dr in dtList.Rows)
                {
                    node = "";
                    user = "";
                    lsFind = lsWorks.FindAll((Workflow.Model.WFWorkItem find) => find.BuDataID == dr["ID"].ToString());
                    if (lsFind != null && lsFind.Count > 0)
                    {
                        foreach (Workflow.Model.WFWorkItem item in lsFind)
                        {
                            if (node != "") { node += ","; user += ","; }
                            node += item.ActTemplateName;
                            user += item.EmployeeName;
                        }
                        dr["CurrentNode"] = node;
                        dr["CurrentUser"] = user;
                    }
                }
            }
            rptList.DataSource = dtList;
            rptList.DataBind();
        }

        protected string GetLinkUrl(string dataId,string subject)
        {
            string script = "";
            if (PageSecurity.Edit)
            {
                if (script.Length > 0) { script += "&nbsp;"; }
                script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_Edit.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" >" + subject + "</a>";
            }
            return script;
        }

		/// <summary>
        /// 得到表格行操作按钮脚本
        /// </summary>
        /// <param name="dataId">记录ID</param>
        /// <param name="buStatus">记录ID</param>
        /// <returns>操作按钮脚本</returns>
        protected string GetButtonScript(string dataId,string tableType,string buStatus)
        {
			string script = "";
            //if (buStatus == ((int)EnumItem.AuditTableStatus.FAppr).ToString()
            //    || buStatus == ((int)EnumItem.AuditTableStatus.FAppr).ToString())
            //{
            //    if (PageSecurity.Delete)
            //    {
            //        if (script.Length > 0) { script += "&nbsp;"; }
            //        script += ScriptHelper.LinkButton.GetGridDeleteButton(dataId, btnDelete.ClientID);
            //    }
            //}
            if (PageSecurity.Edit)
            {
                if (script.Length > 0) { script += "&nbsp;"; }
                script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_Edit.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //if (tableType == "A")
                //{
                //    script += "<a href='#' onclick=\"javascript:openwindow('Bu_AuditTable_View.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //   // script += "<a href='Bu_AuditTable_View.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_blank'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //}
                //else if (tableType == "B")
                //{
                //    script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_B.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //   // script += "<a href='AuditTable_B.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_blank'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //}
                //else if (tableType == "C")
                //{
                //    script += "<a href='#' onclick=\"javascript:openwindow('AuditTable_C.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "','');\" ><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //    //script += "<a href='AuditTable_C.aspx?ID=" + dataId + "&FunctionID=" + FunctionID + "' target='_blank'><img src='" + ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.Edit) + "' alt='处理内部审核作业表' border='0' /></a>";
                //}
            }
            return script;
        }
		
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }
		
		protected void btnQuery_Click(object sender, EventArgs e)
        {
            Bind();
        }
		/// <summary>
        /// 得到选中的记录ID集合
        /// </summary>
        /// <returns></returns>
        private string[] GetSelectedRowKeys()
        {
            string strId = Request["chkID"]+"";
            if (string.IsNullOrEmpty(strId)) { return null; }
            return strId.Split(',');
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
			try
            {
                string[] arrId = GetSelectedRowKeys();
                BaseBusinessLogic<Bu_AuditTable> baseLogic = new BaseBusinessLogic<Bu_AuditTable>();
                baseLogic.DeleteByKey(arrId);
                ScriptHelper.Window.Alert("删除成功！");
                Bind();
            }
            catch (Honestysoft.BaseLibrary.ExceptionHandling.BaseException bex)
            {
                ExceptionHelper.ExceptionDistribute(bex, false);
                ScriptHelper.Window.Alert(bex.Message);
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("删除失败！系统发生了未知错误！");
            }
        }
	}
}
